<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Python的GUI编程和tkinter，Wxpython, 十二惊惶的gitee">
    <meta name="description" content="Python的GUI编程和tkinter，Wxpython
PythonGUI这个内容是我在课程论文准备之初临时去学的一些内容，起初我准备学下tkinter做我课程论文项目的前段显示，但是由于临时的一些变动，我最终是采用了Wxpython的">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>Python的GUI编程和tkinter，Wxpython | 十二惊惶的gitee</title>
    <link rel="icon" type="image/png" href="/shier_jinghuang/favicon.png">
    


    <!-- bg-cover style     -->



<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/awesome/css/all.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/materialize/materialize.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/aos/aos.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/animate/animate.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/lightGallery/css/lightgallery.min.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/css/matery.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/css/my.css">
<link rel="stylesheet" type="text/css" href="/shier_jinghuang/css/dark.css" media="none" onload="if(media!='all')media='all'">




    <link rel="stylesheet" href="/shier_jinghuang/libs/tocbot/tocbot.css">
    <link rel="stylesheet" href="/shier_jinghuang/css/post.css">




    



    <script src="/shier_jinghuang/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/shier_jinghuang/atom.xml" title="十二惊惶的gitee" type="application/atom+xml">
</head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/shier_jinghuang/" class="waves-effect waves-light">
                    
                    <img src="/shier_jinghuang/medias/1.jpg" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">十二惊惶的gitee</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shier_jinghuang/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
  <li>
    <a href="javascript:;" class="waves-effect waves-light" onclick="switchNightMode()" title="深色/浅色模式" >
      <i id="sum-moon-icon" class="fas fa-sun" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/shier_jinghuang/medias/1.jpg" class="logo-img circle responsive-img">
        
        <div class="logo-name">十二惊惶的gitee</div>
        <div class="logo-desc">
            
            犁牛之子骍且角，虽欲勿用，山川其舍诸
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shier_jinghuang/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://gitee.com/Im-so-scared-2/shier_jinghuang" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>十二惊惶
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://gitee.com/Im-so-scared-2/shier_jinghuang" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="十二惊惶" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/shier_jinghuang/medias/featureimages/8.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Python的GUI编程和tkinter，Wxpython</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/shier_jinghuang/tags/Python/">
                                <span class="chip bg-color">Python</span>
                            </a>
                        
                            <a href="/shier_jinghuang/tags/tkinter/">
                                <span class="chip bg-color">tkinter</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/shier_jinghuang/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-category">
                                学习笔记
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2022-07-05
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-07-05
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    3.8k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    15 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/shier_jinghuang/libs/prism/prism.min.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="Python的GUI编程和tkinter，Wxpython"><a href="#Python的GUI编程和tkinter，Wxpython" class="headerlink" title="Python的GUI编程和tkinter，Wxpython"></a>Python的GUI编程和tkinter，Wxpython</h1><blockquote>
<p>PythonGUI这个内容是我在课程论文准备之初临时去学的一些内容，起初我准备学下tkinter做我课程论文项目的前段显示，但是由于临时的一些变动，我最终是采用了Wxpython的方式进行的可视化。当然这两个库在本质上都属于PythonGul。</p>
</blockquote>
<p>[TOC]</p>
<h2 id="PythonGUI介绍："><a href="#PythonGUI介绍：" class="headerlink" title="PythonGUI介绍："></a>PythonGUI介绍：</h2><ul>
<li><strong>Tkinter：</strong> Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口 .Tk 和 Tkinter 可以在大多数的 Unix 平台下使用,同样可以应用在 Windows 和 Macintosh 系统里。Tk8.0 的后续版本可以实现本地窗口风格,并良好地运行在绝大多数平台中。</li>
<li><strong>wxPython：</strong>wxPython 是一款开源软件，是 Python 语言的一套优秀的 GUI 图形库，允许 Python 程序员很方便的创建完整的、功能健全的 GUI 用户界面。</li>
<li><strong>Jython：</strong>Jython 程序可以和 Java 无缝集成。除了一些标准模块，Jython 使用 Java 的模块。Jython 几乎拥有标准的Python 中不依赖于 C 语言的全部模块。比如，Jython 的用户界面将使用 Swing，AWT或者 SWT。Jython 可以被动态或静态地编译成 Java 字节码。</li>
</ul>
<h2 id="tkinter"><a href="#tkinter" class="headerlink" title="tkinter"></a>tkinter</h2><h3 id="根窗体root："><a href="#根窗体root：" class="headerlink" title="根窗体root："></a>根窗体root：</h3><p>根窗体是图像化应用程序的根控制器，是tkinter的底层控件的实例。当导入tkinter模块后，调用 Tk()方法可初始化一个根窗体实例 root ,用 title() 方法可设置其标题文字，用geometry()方法可以设置窗体的大小（以像素为单位）。将其置于主循环中，除非用户关闭，否则程序始终处于运行状态。执行该程序，一个窗体就呈现出来了。在这个主循环的根窗体中，可持续呈现中的其他可视化控件实例，监测事件的发生并执行相应的处理程序 </p>
<p>主窗口位置和大小通过，geometry(‘wxh ± y ± z’)方法进行设置，w为宽度，h为高度，x用于分隔高度和宽度，+x表示距离屏幕左边的距离，-x表示距离屏幕右边的距离，±y同理。</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#代码实现：</span>
<span class="token keyword">from</span> tkinter <span class="token keyword">import</span> <span class="token operator">*</span>
root<span class="token operator">=</span> Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">'我的第一个Python窗体'</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>geometry<span class="token punctuation">(</span><span class="token string">'240x240'</span><span class="token punctuation">)</span> <span class="token comment"># 这里的乘号不是 * ，而是小写英文字母 x</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="GUI组件表："><a href="#GUI组件表：" class="headerlink" title="GUI组件表："></a>GUI组件表：</h3><p>Tkinter的提供各种控件，如按钮，标签和文本框，一个GUI应用程序中使用。这些控件通常被称为控件或者部件。目前有15种Tkinter的部件。</p>
<table>
<thead>
<tr>
<th>Button</th>
<th>按钮控件；在程序中显示按钮。</th>
</tr>
</thead>
<tbody><tr>
<td>Canvas</td>
<td>画布控件；显示图形元素如线条或文本</td>
</tr>
<tr>
<td>Checkbutton</td>
<td>多选框控件；用于在程序中提供多项选择框</td>
</tr>
<tr>
<td>Entry</td>
<td>输入控件；用于显示简单的文本内容</td>
</tr>
<tr>
<td>Frame</td>
<td>框架控件；在屏幕上显示一个矩形区域，多用来作为容器</td>
</tr>
<tr>
<td>Label</td>
<td>标签控件；可以显示文本和位图</td>
</tr>
<tr>
<td>Listbox</td>
<td>列表框控件；在Listbox窗口小部件是用来显示一个字符串列表给用户</td>
</tr>
<tr>
<td>Menubutton</td>
<td>菜单按钮控件，用于显示菜单项。</td>
</tr>
<tr>
<td>Menu</td>
<td>菜单控件；显示菜单栏,下拉菜单和弹出菜单</td>
</tr>
<tr>
<td>Message</td>
<td>消息控件；用来显示多行文本，与label比较类似</td>
</tr>
<tr>
<td>Radiobutton</td>
<td>单选按钮控件；显示一个单选的按钮状态</td>
</tr>
<tr>
<td>Scale</td>
<td>范围控件；显示一个数值刻度，为输出限定范围的数字区间</td>
</tr>
<tr>
<td>Scrollbar</td>
<td>滚动条控件，当内容超过可视化区域时使用，如列表框。.</td>
</tr>
<tr>
<td>Text</td>
<td>文本控件；用于显示多行文本</td>
</tr>
<tr>
<td>Toplevel</td>
<td>容器控件；用来提供一个单独的对话框，和Frame比较类似</td>
</tr>
<tr>
<td>Spinbox</td>
<td>输入控件；与Entry类似，但是可以指定输入范围值</td>
</tr>
<tr>
<td>PanedWindow</td>
<td>PanedWindow是一个窗口布局管理的插件，可以包含一个或者多个子控件。</td>
</tr>
<tr>
<td>LabelFrame</td>
<td>labelframe 是一个简单的容器控件。常用与复杂的窗口布局。</td>
</tr>
<tr>
<td>messagebox</td>
<td>用于显示你应用程序的消息框。</td>
</tr>
</tbody></table>
<h4 id="Python-Tkinter-通用控件属性："><a href="#Python-Tkinter-通用控件属性：" class="headerlink" title="Python Tkinter 通用控件属性："></a>Python Tkinter 通用控件属性：</h4><img src="C:\Users\888888\AppData\Roaming\Typora\typora-user-images\1657019136331.png"  />

<h4 id="Python-Tkinter-按钮组件-Button"><a href="#Python-Tkinter-按钮组件-Button" class="headerlink" title="Python Tkinter 按钮组件 (Button)"></a>Python Tkinter 按钮组件 (Button)</h4><p>按钮组件用于在 Python 应用程序中添加按钮，按钮上可以放上文本或图像，按钮可用于监听用户行为，能够与一个 Python 函数关联，当按钮被按下时，自动调用该函数。 </p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python">w <span class="token operator">=</span> Button <span class="token punctuation">(</span> master<span class="token punctuation">,</span> option<span class="token operator">=</span>value<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">)</span>
<span class="token comment"># master 组件的父容器</span>
<span class="token comment"># option 可选项，这个包括很多内容这些选项可以用键 = 值的形式设置，并以逗号分隔</span>
<span class="token comment"># 包括command（按钮的关联函数），font（文本字体），height（按钮的高度），image（按钮的背景图片），width，text（文本），underline（下划线）等内容</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>

<p> Button按钮的状态有：<code>normal</code>  ,  <code>active</code>  ,  <code>disabled</code></p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> tkinter
<span class="token keyword">import</span> tkinter<span class="token punctuation">.</span>messagebox 
top <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">def</span> <span class="token function">helloCallBack</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    tkinter<span class="token punctuation">.</span>messagebox<span class="token punctuation">.</span>showinfo<span class="token punctuation">(</span><span class="token string">"Hello Python"</span><span class="token punctuation">,</span> <span class="token string">"Hello Runoob"</span><span class="token punctuation">)</span>
B <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>top<span class="token punctuation">,</span> text<span class="token operator">=</span><span class="token string">"点我"</span><span class="token punctuation">,</span> command<span class="token operator">=</span>helloCallBack<span class="token punctuation">)</span>
B<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
top<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>这里稍微做一点说明，这个实例来自于菜鸟教程，而在菜鸟教程上的写法是 import tkMessageBox ,还是有很多区别的，在python3以后的版本中，tkinter应该首字母小写，而tkMessageBox及库中对应的函数应该相应改为<strong>tkinter.messagebox</strong></p>
<p>在具体使用按钮组件进行函数调用时也有对应内容：</p>
<ul>
<li><p>直接调用函数。<strong>参数表达式为“command=函数名”，注意函数名后面不要加括号，也不能传递参数</strong>。如下面的command=run1：</p>
</li>
<li><p>利用匿名函数调用函数和传递参数。参数的表达式为“command=lambda”:函数名（参数列表）</p>
</li>
</ul>
<h5 id="Python-Tkinter-单选按钮控件-Radiobutton"><a href="#Python-Tkinter-单选按钮控件-Radiobutton" class="headerlink" title="Python Tkinter 单选按钮控件(Radiobutton)"></a>Python Tkinter 单选按钮控件(Radiobutton)</h5><p>是为了响应故乡排斥的若干单选项的单击事件以触发运行自定义函数所设的，该控件排除具有共有属性外，还具有显示文本（text）、返回变量（variable）、返回值（value）、响应函数名（command）等重要属性。响应函数名“command=函数名”的用法与Button相同，函数名最后也要加括号。返回变量variable=var通常应预先声明变量的类型var=IntVar()或var=StringVar(),在所调用的函数中方可用var.get()方法获取被选中实例的value值。</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">from</span> tkinter <span class="token keyword">import</span> <span class="token operator">*</span>
<span class="token keyword">def</span> <span class="token function">Mysel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
      dic <span class="token operator">=</span> <span class="token punctuation">&#123;</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token string">'甲'</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token string">'乙'</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">:</span><span class="token string">'丙'</span><span class="token punctuation">&#125;</span>
      s <span class="token operator">=</span> <span class="token string">"您选了"</span> <span class="token operator">+</span> dic<span class="token punctuation">.</span>get<span class="token punctuation">(</span>var<span class="token punctuation">.</span>get<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">"项"</span>
      lb<span class="token punctuation">.</span>config<span class="token punctuation">(</span>text <span class="token operator">=</span> s<span class="token punctuation">)</span>

root <span class="token operator">=</span> Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">'单选按钮'</span><span class="token punctuation">)</span>
lb <span class="token operator">=</span> Label<span class="token punctuation">(</span>root<span class="token punctuation">)</span>
lb<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
var <span class="token operator">=</span> IntVar<span class="token punctuation">(</span><span class="token punctuation">)</span>
rd1 <span class="token operator">=</span> Radiobutton<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">"甲"</span><span class="token punctuation">,</span>variable<span class="token operator">=</span>var<span class="token punctuation">,</span>value<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span>command<span class="token operator">=</span>Mysel<span class="token punctuation">)</span>
rd1<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
rd2 <span class="token operator">=</span> Radiobutton<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">"乙"</span><span class="token punctuation">,</span>variable<span class="token operator">=</span>var<span class="token punctuation">,</span>value<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span>command<span class="token operator">=</span>Mysel<span class="token punctuation">)</span>
rd2<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
rd3 <span class="token operator">=</span> Radiobutton<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">"丙"</span><span class="token punctuation">,</span>variable<span class="token operator">=</span>var<span class="token punctuation">,</span>value<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">,</span>command<span class="token operator">=</span>Mysel<span class="token punctuation">)</span>
rd3<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h5 id="Python-Tkinter-复选框（Checkbutton）"><a href="#Python-Tkinter-复选框（Checkbutton）" class="headerlink" title="Python Tkinter 复选框（Checkbutton）"></a>Python Tkinter 复选框（Checkbutton）</h5><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment"># 定义方法</span>
w <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Checkbutton<span class="token punctuation">(</span> master<span class="token punctuation">,</span> option<span class="token operator">=</span>value<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">)</span>
<span class="token comment"># 在python3中，复选框的定义方式发生了略微改变</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>

<p><strong>复选框</strong>：(Checkbutton) 是为了返回多个选项值的交互控件，通常不直接触发函数的执行。该控件除具有共有属性外，还具有显示文本（text）、返回变量（variable）、选中返回值（onvalue）和未选中默认返回值（offvalue）等重要属性。返回变量variable=var 通常可以预先逐项分别声明变量的类型var=IntVar() (默认)或 var=StringVar(), 在所调用的函数中方可分别调用 var.get()方法 取得被选中实例的 onvalue或offvalue值。复选框实例通常还可分别利用 select()、deselect()和 toggle() 方法对其进行选中、清除选中和反选操作。</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#简单样例：</span>
<span class="token keyword">import</span> tkinter<span class="token punctuation">.</span>messagebox
<span class="token keyword">import</span> tkinter
top <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
CheckVar1 <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>IntVar<span class="token punctuation">(</span><span class="token punctuation">)</span>
CheckVar2 <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>IntVar<span class="token punctuation">(</span><span class="token punctuation">)</span>
C1 <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Checkbutton<span class="token punctuation">(</span>top<span class="token punctuation">,</span> text<span class="token operator">=</span><span class="token string">"RUNOOB"</span><span class="token punctuation">,</span> variable<span class="token operator">=</span>CheckVar1<span class="token punctuation">,</span>onvalue<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> offvalue<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">,</span>width<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">)</span>
C2 <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Checkbutton<span class="token punctuation">(</span>top<span class="token punctuation">,</span> text<span class="token operator">=</span><span class="token string">"GOOGLE"</span><span class="token punctuation">,</span> variable<span class="token operator">=</span>CheckVar2<span class="token punctuation">,</span>onvalue<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> offvalue<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">)</span>
C1<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
C2<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
top<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="Python-Tkinter-标签控件（Label）及消息控件（Message）"><a href="#Python-Tkinter-标签控件（Label）及消息控件（Message）" class="headerlink" title="Python Tkinter 标签控件（Label）及消息控件（Message）"></a>Python Tkinter 标签控件（Label）及消息控件（Message）</h4><p>Python Tkinter 标签控件（Label）指定的窗口中显示的文本和图像。如果需要使用一行或多行且不应该被用户更改的标签控件需要用label控件。</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python">w <span class="token operator">=</span> Label <span class="token punctuation">(</span> master<span class="token punctuation">,</span> option<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">)</span>
<span class="token comment"># option 可选项内容与Button的可选项内容相近，但也有wraplength（标签文本显示行数）</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#一个简单样例：</span>
<span class="token keyword">import</span> tkinter <span class="token keyword">as</span> tk
root <span class="token operator">=</span> tk<span class="token punctuation">.</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
w <span class="token operator">=</span> tk<span class="token punctuation">.</span>Label<span class="token punctuation">(</span>root<span class="token punctuation">,</span> text<span class="token operator">=</span><span class="token string">"Hello RUNOOB!"</span><span class="token punctuation">)</span>
w<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p><strong>标签（Label）</strong>和 <strong>消息（Message）</strong>：除了单行与多行的不同外，属性和用法基本一致，用于呈现文本信息。</p>
<p>值得注意的是：属性text通常用于实例在第一次呈现时的固定文本，而如果需要在程序执行后发生变化，则可以使用下列方法之一实现：</p>
<p>1、用控件实例的configure()方法来改变属性text的值，可使显示的文本发生变化；</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> tkinter
<span class="token keyword">import</span> time

<span class="token keyword">def</span> <span class="token function">gettime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
      timestr <span class="token operator">=</span> time<span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">"%H:%M:%S"</span><span class="token punctuation">)</span> <span class="token comment"># 获取当前的时间并转化为字符串</span>
      lb<span class="token punctuation">.</span>configure<span class="token punctuation">(</span>text<span class="token operator">=</span>timestr<span class="token punctuation">)</span>   <span class="token comment"># 重新设置标签文本</span>
      root<span class="token punctuation">.</span>after<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span>gettime<span class="token punctuation">)</span> <span class="token comment"># 每隔1s调用函数 gettime 自身获取时间</span>

root <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">'时钟'</span><span class="token punctuation">)</span>

lb <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Label<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span>fg<span class="token operator">=</span><span class="token string">'blue'</span><span class="token punctuation">,</span>font<span class="token operator">=</span><span class="token punctuation">(</span><span class="token string">"黑体"</span><span class="token punctuation">,</span><span class="token number">80</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
lb<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
gettime<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<p>2、先定义一个tkinter的内部类型变量var=StringVar() 的值也可以使显示文本发生变化。</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> tkinter
<span class="token keyword">import</span> time

<span class="token keyword">def</span> <span class="token function">gettime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
      var<span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span>time<span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">"%H:%M:%S"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>   <span class="token comment"># 获取当前时间</span>
      root<span class="token punctuation">.</span>after<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span>gettime<span class="token punctuation">)</span>   <span class="token comment"># 每隔1s调用函数 gettime 自身获取时间</span>

root <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>title<span class="token punctuation">(</span><span class="token string">'时钟'</span><span class="token punctuation">)</span>
var<span class="token operator">=</span>tkinter<span class="token punctuation">.</span>StringVar<span class="token punctuation">(</span><span class="token punctuation">)</span>
lb <span class="token operator">=</span> tkinter<span class="token punctuation">.</span>Label<span class="token punctuation">(</span>root<span class="token punctuation">,</span>textvariable<span class="token operator">=</span>var<span class="token punctuation">,</span>fg<span class="token operator">=</span><span class="token string">'blue'</span><span class="token punctuation">,</span>font<span class="token operator">=</span><span class="token punctuation">(</span><span class="token string">"黑体"</span><span class="token punctuation">,</span><span class="token number">80</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
lb<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
gettime<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="Python-Tkinter-文本组件-Text"><a href="#Python-Tkinter-文本组件-Text" class="headerlink" title="Python Tkinter 文本组件 (Text)"></a>Python Tkinter 文本组件 (Text)</h4><img src="C:\Users\888888\AppData\Roaming\Typora\typora-user-images\1657025434153.png"  />

<p> 上表位置的取值可为整数，浮点数或END（末尾），例如0.0表示第0列第0行</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">from</span> tkinter <span class="token keyword">import</span> <span class="token operator">*</span>
<span class="token keyword">import</span> time
<span class="token keyword">import</span> datetime
<span class="token keyword">def</span> <span class="token function">gettime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
       s<span class="token operator">=</span><span class="token builtin">str</span><span class="token punctuation">(</span>datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span>now<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">'\n'</span>
       txt<span class="token punctuation">.</span>insert<span class="token punctuation">(</span>END<span class="token punctuation">,</span>s<span class="token punctuation">)</span>
       root<span class="token punctuation">.</span>after<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span>gettime<span class="token punctuation">)</span>  <span class="token comment"># 每隔1s调用函数 gettime 自身获取时间</span>
root<span class="token operator">=</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>geometry<span class="token punctuation">(</span><span class="token string">'320x240'</span><span class="token punctuation">)</span>
txt<span class="token operator">=</span>Text<span class="token punctuation">(</span>root<span class="token punctuation">)</span>
txt<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
gettime<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<ul>
<li><strong>输入框（Entry）</strong>：通常作为功能比较单一的接收单行文本输入的控件，虽然也有许多对其中文本进行操作的方法，但通常用的只有取值方法get()和用于删除文本的delete(起始位置，终止位置)，例如：清空输入框为delete(0，END)。</li>
</ul>
<h3 id="GUI应用程序类的通常写法"><a href="#GUI应用程序类的通常写法" class="headerlink" title="GUI应用程序类的通常写法"></a>GUI应用程序类的通常写法</h3><p>通过类application组织整个GUI程序，类application及继承了frame，及通过继承拥有了父类的特性。通过构造函数<code>_init_</code>()初始化窗口中的对象，通过createwidgets()方法创建窗口中的对象。</p>
<p>Frama框架是一个tkinter组件，表示一个矩形的区域。frame一般作为容器使用，可以放置其他组件，从而实现复杂的布局。</p>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> tkinter <span class="token keyword">as</span> tk
<span class="token keyword">class</span> <span class="token class-name">Application</span><span class="token punctuation">(</span>tk<span class="token punctuation">.</span>Frame<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> master<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token builtin">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>__init__<span class="token punctuation">(</span>master<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>master <span class="token operator">=</span> master
        self<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>create_widgets<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">def</span> <span class="token function">create_widgets</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>hi_there <span class="token operator">=</span> tk<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>hi_there<span class="token punctuation">[</span><span class="token string">"text"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"Hello World\n(click me)"</span>
        self<span class="token punctuation">.</span>hi_there<span class="token punctuation">[</span><span class="token string">"command"</span><span class="token punctuation">]</span> <span class="token operator">=</span> self<span class="token punctuation">.</span>say_hi
        self<span class="token punctuation">.</span>hi_there<span class="token punctuation">.</span>pack<span class="token punctuation">(</span>side<span class="token operator">=</span><span class="token string">"top"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>quit <span class="token operator">=</span> tk<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">,</span> text<span class="token operator">=</span><span class="token string">"QUIT"</span><span class="token punctuation">,</span> fg<span class="token operator">=</span><span class="token string">"red"</span><span class="token punctuation">,</span>
                              command<span class="token operator">=</span>self<span class="token punctuation">.</span>master<span class="token punctuation">.</span>destroy<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>quit<span class="token punctuation">.</span>pack<span class="token punctuation">(</span>side<span class="token operator">=</span><span class="token string">"bottom"</span><span class="token punctuation">)</span>
    <span class="token keyword">def</span> <span class="token function">say_hi</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"hi there, everyone!"</span><span class="token punctuation">)</span>
root <span class="token operator">=</span> tk<span class="token punctuation">.</span>Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
app <span class="token operator">=</span> Application<span class="token punctuation">(</span>master<span class="token operator">=</span>root<span class="token punctuation">)</span>
app<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="几何管理（控件布局）"><a href="#几何管理（控件布局）" class="headerlink" title="几何管理（控件布局）"></a>几何管理（控件布局）</h3><p>Tkinter控件有特定的几何状态管理方法，管理整个控件区域组织，以下是Tkinter公开的几何管理类：包、网格、位置</p>
<table>
<thead>
<tr>
<th>几何方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>pack()</td>
<td>包装；</td>
</tr>
<tr>
<td>grid()</td>
<td>网格；</td>
</tr>
<tr>
<td>place()</td>
<td>位置；</td>
</tr>
</tbody></table>
<h4 id="Pack-布局方式："><a href="#Pack-布局方式：" class="headerlink" title="Pack()布局方式："></a>Pack()布局方式：</h4><p>Pack()方法： 是一种简单的布局方法，如果不加参数的默认方式，将按布局语句的先后，以最小占用空间的方式自上而下地排列控件实例，并且保持控件本身的最小尺寸。</p>
<p>使用pack()方法可设置 fill、side 等属性参数。</p>
<table>
<thead>
<tr>
<th>pack()函数的属性</th>
<th>取值的对应意义</th>
</tr>
</thead>
<tbody><tr>
<td>fill=X/y/BOTH</td>
<td>允许控件向水平方向、垂直方向或二维伸展填充未被占用控件</td>
</tr>
<tr>
<td>side=left/right/bottom</td>
<td>表示本控件实例的布局相对于下一个控件实例的方位</td>
</tr>
</tbody></table>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">from</span> tkinter <span class="token keyword">import</span>  <span class="token operator">*</span>
root <span class="token operator">=</span> Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
lbred <span class="token operator">=</span> Label<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">"Red"</span><span class="token punctuation">,</span>fg<span class="token operator">=</span><span class="token string">"Red"</span><span class="token punctuation">,</span>relief<span class="token operator">=</span>GROOVE<span class="token punctuation">)</span>
lbred<span class="token punctuation">.</span>pack<span class="token punctuation">(</span><span class="token punctuation">)</span>
lbgreen <span class="token operator">=</span> Label<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">"绿色"</span><span class="token punctuation">,</span>fg<span class="token operator">=</span><span class="token string">"green"</span><span class="token punctuation">,</span>relief<span class="token operator">=</span>GROOVE<span class="token punctuation">)</span>
lbgreen<span class="token punctuation">.</span>pack<span class="token punctuation">(</span>side<span class="token operator">=</span>RIGHT<span class="token punctuation">)</span>
lbblue <span class="token operator">=</span> Label<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token string">"蓝"</span><span class="token punctuation">,</span>fg<span class="token operator">=</span><span class="token string">"blue"</span><span class="token punctuation">,</span>relief<span class="token operator">=</span>GROOVE<span class="token punctuation">)</span>
lbblue<span class="token punctuation">.</span>pack<span class="token punctuation">(</span>fill<span class="token operator">=</span>X<span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h4 id="grid-布局方式："><a href="#grid-布局方式：" class="headerlink" title="grid()布局方式："></a>grid()布局方式：</h4><p><strong>grid()方法</strong>：是基于网格的布局。先虚拟一个二维表格，再在该表格中布局控件实例。由于在虚拟表格的单元中所布局的控件实例大小不一，单元格也没有固定或均一的大小，因此其仅用于布局的定位。pack()方法与grid()方法不能混合使用。<br> <strong>grid()方法常用布局参数如下：</strong></p>
<ul>
<li> <strong>column:</strong> 控件实例的起始列，最左边为第0列。</li>
<li> <strong>columnspan:</strong> 控件实例所跨越的列数，默认为1列。</li>
<li> <strong>ipadx,ipady:</strong> 控件实例所呈现区域内部的像素数，用来设置控件实例的大小。</li>
<li> <strong>padx,pady:</strong> 控件实例所占据空间像素数，用来设置实例所在单元格的大小。</li>
<li> <strong>row:</strong> 控件实例的起始行，最上面为第0行。</li>
<li> <strong>rowspan:</strong> 控件实例的起始行数，默认为1行。</li>
</ul>
<h4 id="place-布局方法："><a href="#place-布局方法：" class="headerlink" title="place()布局方法："></a>place()布局方法：</h4><p><strong>place()方法</strong>：根据控件实例在父容器中的绝对或相对位置参数进行布局。其常用布局参数如下：</p>
<ul>
<li><strong>x,y：</strong>控件实例在根窗体中水平和垂直方向上的其实位置（单位为像素）。注意，根窗体左上角为0,0,水平向右，垂直向下为正方向。</li>
<li><strong>relx,rely：</strong>控件实例在根窗体中水平和垂直方向上起始布局的相对位置。即相对于根窗体宽和高的比例位置，取值在<code>0.0~1.0</code>之间。</li>
<li><strong>height,width：</strong>控件实例本身的高度和宽度（单位为像素）。</li>
<li><strong>relheight,relwidth：</strong>控件实例相对于根窗体的高度和宽度比例，取值在<code>0.0~1.0</code>之间。</li>
<li>利用place()方法配合relx,rely和relheight,relwidth参数所得的到的界面可自适应根窗体尺寸的大小。place()方法与grid()方法可以混合使用。如下例子：利用place()方法排列消息（多行标签）。</li>
</ul>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#参考样例：</span>
<span class="token keyword">from</span> tkinter <span class="token keyword">import</span> <span class="token operator">*</span>
root <span class="token operator">=</span> Tk<span class="token punctuation">(</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>geometry<span class="token punctuation">(</span><span class="token string">'320x240'</span><span class="token punctuation">)</span>
msg1 <span class="token operator">=</span> Message<span class="token punctuation">(</span>root<span class="token punctuation">,</span>text<span class="token operator">=</span><span class="token triple-quoted-string string">'''我的水平起始位置相对窗体 0.2，垂直起始位置为绝对位置 80 像素，我的高度是窗体高度的0.4，宽度是200像素'''</span><span class="token punctuation">,</span>relief<span class="token operator">=</span>GROOVE<span class="token punctuation">)</span>
msg1<span class="token punctuation">.</span>place<span class="token punctuation">(</span>relx<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token number">80</span><span class="token punctuation">,</span>relheight<span class="token operator">=</span><span class="token number">0.4</span><span class="token punctuation">,</span>width<span class="token operator">=</span><span class="token number">200</span><span class="token punctuation">)</span>
root<span class="token punctuation">.</span>mainloop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h2 id="Wxpython"><a href="#Wxpython" class="headerlink" title="Wxpython"></a>Wxpython</h2><blockquote>
<p>Wxpython这个是我最后采用的gui库，倒不是因为有多大去别，主要是我找到了一个自动生成Wxpython的代码段的小程序，我最后选择了wxpython。</p>
</blockquote>
<pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment"># -*- coding:utf-8 -*-</span>
<span class="token keyword">import</span> wx<span class="token punctuation">.</span>lib<span class="token punctuation">.</span>agw<span class="token punctuation">.</span>hyperlink <span class="token keyword">as</span> lib_hyperlink
<span class="token keyword">import</span> wx

<span class="token keyword">class</span> <span class="token class-name">Frame</span><span class="token punctuation">(</span>wx<span class="token punctuation">.</span>Frame<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        wx<span class="token punctuation">.</span>Frame<span class="token punctuation">.</span>__init__<span class="token punctuation">(</span>self<span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">,</span> title<span class="token operator">=</span><span class="token string">'网站源代码下载器'</span><span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">800</span><span class="token punctuation">,</span> <span class="token number">300</span><span class="token punctuation">)</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'frame'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">541072384</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>qdck <span class="token operator">=</span> wx<span class="token punctuation">.</span>Panel<span class="token punctuation">(</span>self<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>Centre<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Button<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">46</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">350</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">)</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">'下载'</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'button'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1<span class="token punctuation">.</span>SetAuthNeeded<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>an1<span class="token punctuation">.</span>Bind<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>EVT_BUTTON<span class="token punctuation">,</span>self<span class="token punctuation">.</span>an1_anbdj<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bjk1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>TextCtrl<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">150</span><span class="token punctuation">,</span> <span class="token number">85</span><span class="token punctuation">)</span><span class="token punctuation">,</span>value<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'text'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">4096</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bjk1<span class="token punctuation">.</span>SetMaxLength<span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq1 <span class="token operator">=</span> wx<span class="token punctuation">.</span>StaticText<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">365</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">235</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">'请输入需要下载的链接'</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>style<span class="token operator">=</span><span class="token number">2321</span><span class="token punctuation">)</span>
        bq1_字体 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Font<span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">,</span><span class="token number">74</span><span class="token punctuation">,</span><span class="token number">90</span><span class="token punctuation">,</span><span class="token number">700</span><span class="token punctuation">,</span><span class="token boolean">False</span><span class="token punctuation">,</span><span class="token string">'Microsoft YaHei UI'</span><span class="token punctuation">,</span><span class="token number">28</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>bq1<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>bq1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1 <span class="token operator">=</span> lib_hyperlink<span class="token punctuation">.</span>HyperLinkCtrl<span class="token punctuation">(</span>self<span class="token punctuation">.</span>qdck<span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">28</span><span class="token punctuation">)</span><span class="token punctuation">,</span>pos<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">380</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">,</span>name<span class="token operator">=</span><span class="token string">'staticText'</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">'使用说明'</span><span class="token punctuation">,</span>URL<span class="token operator">=</span><span class="token string">'https://im-so-scared-2.gitee.io/shier_jinghuang/'</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetToolTip<span class="token punctuation">(</span>wx<span class="token punctuation">.</span>ToolTip<span class="token punctuation">(</span><span class="token string">'使用说明'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        cjljkL1_字体 <span class="token operator">=</span> wx<span class="token punctuation">.</span>Font<span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">70</span><span class="token punctuation">,</span><span class="token number">90</span><span class="token punctuation">,</span><span class="token number">400</span><span class="token punctuation">,</span><span class="token boolean">True</span><span class="token punctuation">,</span><span class="token string">'Microsoft YaHei UI'</span><span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetFont<span class="token punctuation">(</span>cjljkL1_字体<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>cjljkL1<span class="token punctuation">.</span>SetForegroundColour<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">def</span> <span class="token function">an1_anbdj</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span>event<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment">#print('an1,按钮被单击')</span>
        <span class="token keyword">pass</span>
<span class="token keyword">class</span> <span class="token class-name">myApp</span><span class="token punctuation">(</span>wx<span class="token punctuation">.</span>App<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">def</span>  <span class="token function">OnInit</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>frame <span class="token operator">=</span> Frame<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>frame<span class="token punctuation">.</span>Show<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">True</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    app <span class="token operator">=</span> myApp<span class="token punctuation">(</span><span class="token punctuation">)</span>
    app<span class="token punctuation">.</span>MainLoop<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>


                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/shier_jinghuang/about" rel="external nofollow noreferrer">十二惊惶</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://im-so-scared-2.gitee.io/shier_jinghuang/shier_jinghuang/2022/07/05/python%E7%9A%84GUI%E7%BC%96%E7%A8%8B%E5%92%8Ctkinter/">https://im-so-scared-2.gitee.io/shier_jinghuang/shier_jinghuang/2022/07/05/python%E7%9A%84GUI%E7%BC%96%E7%A8%8B%E5%92%8Ctkinter/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/shier_jinghuang/about" target="_blank">十二惊惶</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/shier_jinghuang/tags/Python/">
                                    <span class="chip bg-color">Python</span>
                                </a>
                            
                                <a href="/shier_jinghuang/tags/tkinter/">
                                    <span class="chip bg-color">tkinter</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/shier_jinghuang/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/shier_jinghuang/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/shier_jinghuang/2022/07/06/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AE%9E%E9%AA%8C%E6%8A%A5%E5%91%8A/">
                    <div class="card-image">
                        
                        
                        <img src="/shier_jinghuang/medias/featureimages/16.jpg" class="responsive-img" alt="数据库实验报告">
                        
                        <span class="card-title">数据库实验报告</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2022-07-06
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shier_jinghuang/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-category">
                                    学习笔记
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shier_jinghuang/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/">
                        <span class="chip bg-color">数据库</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/shier_jinghuang/2022/07/05/%E8%AF%BE%E7%A8%8B%E8%AE%BA%E6%96%87-%E6%BA%90%E4%BB%A3%E7%A0%81%E4%B8%8B%E8%BD%BD%E5%99%A8%E7%9A%84%E8%AE%BE%E8%AE%A1%E5%AE%9E%E7%8E%B0/">
                    <div class="card-image">
                        
                        
                        <img src="/shier_jinghuang/medias/featureimages/6.jpg" class="responsive-img" alt="课程论文-源代码下载器的设计实现">
                        
                        <span class="card-title">课程论文-源代码下载器的设计实现</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-07-05
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shier_jinghuang/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-category">
                                    学习笔记
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shier_jinghuang/tags/%E8%AF%BE%E7%A8%8B%E8%AE%BA%E6%96%87/">
                        <span class="chip bg-color">课程论文</span>
                    </a>
                    
                    <a href="/shier_jinghuang/tags/Python%E7%88%AC%E8%99%AB/">
                        <span class="chip bg-color">Python爬虫</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeBlockFuction.js"></script>


  <!-- 是否加载使用自带的 prismjs. -->
  <script type="text/javascript" src="/shier_jinghuang/libs/prism/prism.min.js"></script>


<!-- 代码语言 -->

<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/shier_jinghuang/libs/codeBlock/codeShrink.js"></script>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/shier_jinghuang/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/shier_jinghuang/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/shier_jinghuang/libs/aplayer/APlayer.min.js"></script>
<script src="/shier_jinghuang/libs/aplayer/Meting.min.js"></script>

    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2023</span>
            
            <a href="/shier_jinghuang/about" target="_blank">十二惊惶</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">289.6k</span>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:1181062873@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1181062873" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1181062873" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/shier_jinghuang/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/shier_jinghuang/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 白天和黑夜主题 -->
<div class="stars-con">
    <div id="stars"></div>
    <div id="stars2"></div>
    <div id="stars3"></div>  
</div>

<script>
    function switchNightMode() {
        $('<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"></div></div>').appendTo($('body')),
        setTimeout(function () {
            $('body').hasClass('DarkMode') 
            ? ($('body').removeClass('DarkMode'), localStorage.setItem('isDark', '0'), $('#sum-moon-icon').removeClass("fa-sun").addClass('fa-moon')) 
            : ($('body').addClass('DarkMode'), localStorage.setItem('isDark', '1'), $('#sum-moon-icon').addClass("fa-sun").removeClass('fa-moon')),
            
            setTimeout(function () {
            $('.Cuteen_DarkSky').fadeOut(1e3, function () {
                $(this).remove()
            })
            }, 2e3)
        })
    }
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/shier_jinghuang/libs/materialize/materialize.min.js"></script>
    <script src="/shier_jinghuang/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/shier_jinghuang/libs/aos/aos.js"></script>
    <script src="/shier_jinghuang/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/shier_jinghuang/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/shier_jinghuang/js/matery.js"></script>

    

    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/shier_jinghuang/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/shier_jinghuang/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/shier_jinghuang/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/shier_jinghuang/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
